import { Req, type Resp } from '@/utils/request'

// 获取视频列表
export function getVideosList(query: {
  pageNum: number
  pageSize: number
  keyword: string | null | ''
}): Promise<Resp<PageInfo<Videos>>> {
  return Req.$get<PageInfo<Videos>>('/video/list', query)
}

// 获取视频列表
export function getVideoInfo(id: number): Promise<Resp<Videos>> {
  return Req.$get<Videos>('/video/info', { id })
}

// 获取剧集列表
export function getVideoParts(id: number): Promise<Resp<VideoPart[]>> {
  return Req.$get<VideoPart[]>('/video/parts', { id })
}

// 删除剧集
export function deleteVideoParts(id: number): Promise<Resp<any>> {
  return Req.$delete<any>(`/video/part/delete`, {}, { id })
}

// 剧集文件列表
export function getVideoPartsFilesList(id: number): Promise<Resp<string[]>> {
  return Req.$get<string[]>(`/video/part/file/list`, { id })
}

// 添加剧集
export function addPart(VideoPart: VideoPart): Promise<Resp<VideoPart>> {
  return Req.$post<VideoPart>(`/video/part/add`, VideoPart)
}

// 上传文件
export function uploadPartFile(partId: number, files: File[]): Promise<Resp<any>> {
  return Req.$uploadFile('/video/part/file/upload', 'file', files, { id: partId })
}

// 删除文件
export function deletePartFile(partId: number, filename: string): Promise<Resp<any>> {
  return Req.$delete('/video/part/file/delete', {}, { id: partId, filename })
}

// 清空文件
export function clearPartFile(partId: number): Promise<Resp<any>> {
  return Req.$delete('/video/part/file/clear', {}, { id: partId })
}

// 上传封面文件
export function uploadCover(partId: number, files: File[]): Promise<Resp<any>> {
  return Req.$uploadFile('/video/cover', 'file', files, { id: partId })
}

// 添加视频
export function addVideo(video: Videos): Promise<Resp<any>> {
  return Req.$post('/video/add', video, {})
}

// 删除视频
export function deleteVideo(videoId: number): Promise<Resp<any>> {
  return Req.$delete('/video/delete', {}, { id: videoId })
}

// 编辑视频
export function updateVideo(video: Videos): Promise<Resp<any>> {
  return Req.$put('/video/update', video, {})
}
